package com.threeox.commonlibrary.entity.engine.request;

import com.threeox.commonlibrary.entity.base.BaseObj;
import com.threeox.commonlibrary.entity.engine.request.base.BaseRequestMsg;
import com.threeox.commonlibrary.entity.engine.request.file.FileRequestMsg;
import com.threeox.commonlibrary.entity.engine.request.network.NetWorkRequestMsg;
import com.threeox.commonlibrary.entity.engine.request.sharedpre.SharedPreReqMsg;
import com.threeox.commonlibrary.entity.engine.request.sqlite.SqliteRequestMsg;
import com.threeox.utillibrary.util.EmptyUtils;
import com.threeox.utillibrary.util.res.StringHelper;

/**
 *
 * @ClassName: RequestMsg
 *
 * @Description: TODO(请求数据对象)
 *
 * @author 赵屈犇
 *
 * @date 创建时间: 2017/7/4 14:41
 *
 * @version 1.0
 *
 */
public class RequestMsg extends BaseObj {

    // 网络请求对象
    private NetWorkRequestMsg networdRequest;
    // 本地SqlIte请求对象
    private SqliteRequestMsg sqliteRequest;
    // SharedPreferences请求对象
    private SharedPreReqMsg sharedPreRequest;
    // 本地文件请求对象
    private FileRequestMsg fileRequest;
    // 通过Intent传递数据的对象
    private IntentRequestMsg intentReqMsg;
    // 用户自定义的请求对象
    private BaseRequestMsg customRequest;
    // 响应事件时dialog的展示
    private String loadMessage;

    public void initData(StringHelper stringHelper) {
        if (null != networdRequest) {
            networdRequest.initData(stringHelper);
        }
        if (null != sqliteRequest) {
            sqliteRequest.initData(stringHelper);
        }
        if (null != intentReqMsg) {
            intentReqMsg.initData(stringHelper);
        }
        if (null != sharedPreRequest) {
            sharedPreRequest.initData(stringHelper);
        }
        if (null != customRequest) {
            customRequest.initData(stringHelper, EmptyUtils.isNotEmpty(customRequest.getRequestType()) ? customRequest.getRequestType() : "customRequest");
        }
        if (EmptyUtils.isEmpty(loadMessage)) {
            this.loadMessage = "正在请求...";
        } else {
            this.loadMessage = stringHelper.getString(loadMessage);
        }
    }

    public NetWorkRequestMsg getNetwordRequest() {
        return networdRequest;
    }

    public void setNetwordRequest(NetWorkRequestMsg networdRequest) {
        this.networdRequest = networdRequest;
    }

    public SqliteRequestMsg getSqliteRequest() {
        return sqliteRequest;
    }

    public void setSqliteRequest(SqliteRequestMsg sqliteRequest) {
        this.sqliteRequest = sqliteRequest;
    }

    public SharedPreReqMsg getSharedPreRequest() {
        return sharedPreRequest;
    }

    public void setSharedPreRequest(SharedPreReqMsg sharedPreRequest) {
        this.sharedPreRequest = sharedPreRequest;
    }

    public FileRequestMsg getFileRequest() {
        return fileRequest;
    }

    public void setFileRequest(FileRequestMsg fileRequest) {
        this.fileRequest = fileRequest;
    }

    public IntentRequestMsg getIntentReqMsg() {
        return intentReqMsg;
    }

    public void setIntentReqMsg(IntentRequestMsg intentReqMsg) {
        this.intentReqMsg = intentReqMsg;
    }

    public BaseRequestMsg getCustomRequest() {
        return customRequest;
    }

    public void setCustomRequest(BaseRequestMsg customRequest) {
        this.customRequest = customRequest;
    }

    public String getLoadMessage() {
        return loadMessage;
    }

    public void setLoadMessage(String loadMessage) {
        this.loadMessage = loadMessage;
    }

    /**
     * 是否存在一项
     *
     * @return
     */
    public boolean isEmpty() {
        return ((null != networdRequest) || (null != sqliteRequest) || (null != sharedPreRequest)
                || (null != fileRequest) || (null != intentReqMsg) || (null != customRequest));
    }

    /**
     * 初始化所有参数
     *
     * @param intent
     *
     * public void initAllParams(Intent intent) {
     *  initReplaceParam(intent);
     *  initRequestParam(intent);
     *  initOpertionParams(intent);
     *  initRequestHeaders(intent);
     *  if (null != intentReqMsg)
     *      intentReqMsg.initAllParams(intent);
     * }
     *
     */

    /**
     * 初始化所有参数
     *
     * @param data
     */
    public void initAllParams(Object data) {
        initReplaceParam(data);
        initRequestParam(data);
        initOpertionParams(data);
        initRequestHeaders(data);
    }

    /**
     * 初始化代替参数
     *
     * @param intent
     *
     * public void initReplaceParam(Intent intent) {
     *  if (null != networdRequest)
     *      networdRequest.initReplaceParam(intent);
     *  if (null != sqliteRequest)
     *      sqliteRequest.initReplaceParam(intent);
     *  if (null != customRequest)
     *      customRequest.initReplaceParam(intent);
     *  }
     */

    /**
     * 初始化代替参数
     *
     * @param data
     */
    public void initReplaceParam(Object data) {
        if (null != networdRequest) {
            networdRequest.initReplaceParam(data);
        }
        if (null != sqliteRequest) {
            sqliteRequest.initReplaceParam(data);
        }
        if (null != customRequest) {
            customRequest.initReplaceParam(data);
        }
        if (null != sharedPreRequest) {
            sharedPreRequest.initReplaceParam(data);
        }
    }


    /**
     * 初始化请求参数
     *
     * @param intent
     * public void initRequestParam(Intent intent) {
     *  if (null != networdRequest)
     *      networdRequest.initRequestParam(intent);
     *  if (null != sqliteRequest)
     *      sqliteRequest.initRequestParam(intent);
     *  if (null != customRequest)
     *      customRequest.initRequestParam(intent);
     *  }
     *
     */

    /**
     * 传入请求参数
     *
     * @param key
     * @param value
     */
    public void putRequestParam(String key, Object value) {
        if (null != networdRequest) {
            networdRequest.putRequestParam(key, value);
        }
        if (null != sqliteRequest) {
            sqliteRequest.putRequestParam(key, value);
        }
        if (null != customRequest) {
            customRequest.putRequestParam(key, value);
        }
        if (null != sharedPreRequest) {
            sharedPreRequest.putRequestParam(key, value);
        }
    }

    /**
     * 删除请求参数 根据key
     *
     * @param key
     */
    public void removeRequestParam(String key) {
        if (null != networdRequest) {
            networdRequest.removeRequestParam(key);
        }
        if (null != sqliteRequest) {
            sqliteRequest.removeRequestParam(key);
        }
        if (null != customRequest) {
            customRequest.removeRequestParam(key);
        }
        if (null != sharedPreRequest) {
            sharedPreRequest.removeRequestParam(key);
        }
    }

    /**
     * 初始化请求参数
     *
     * @param data
     */
    public void initRequestParam(Object data) {
        if (null != networdRequest) {
            networdRequest.initRequestParam(data);
        }
        if (null != sqliteRequest) {
            sqliteRequest.initRequestParam(data);
        }
        if (null != customRequest) {
            customRequest.initRequestParam(data);
        }
        if (null != sharedPreRequest) {
            sharedPreRequest.initRequestParam(data);
        }
    }

    /**
     * 初始化请求头信息
     *
     * @param intent
     *
     * public void initRequestHeaders(Intent intent) {
     *  if (null != networdRequest)
     *      networdRequest.initRequestHeaders(intent);
     * }
     *
     */

    /**
     * 初始化请求头信息
     *
     * @param data
     */
    public void initRequestHeaders(Object data) {
        if (null != networdRequest)
            networdRequest.initRequestHeaders(data);
    }

    /**
     * 初始化Sqlite 的操作参数
     *
     * @param intent
     *
     * public void initOpertionParams(Intent intent) {
     *  if (null != sqliteRequest)
     *      sqliteRequest.initOpertionParams(intent);
     * }
     */

    /**
     * 初始化Sqlite 的操作参数
     *
     * @param data
     */
    public void initOpertionParams(Object data) {
        if (null != sqliteRequest)
            sqliteRequest.initOpertionParams(data);
    }
}
